<template>
  <!--故障管理--维修历史-->
  <div class="content-area">
    <!-- 位置模块 -->
    <HeadTop></HeadTop>
    <div class="search-area">
      <div class="search-content">
        <div class="search-item"><span>注册代码:</span>
          <el-input placeholder="请输入内容" v-model="searchMsg.elCode" clearable></el-input>
        </div>
        <div class="search-item"><span>维修责任人:</span><!--维修责任人-->
          <el-input placeholder="请输入内容" v-model="searchMsg.repUserName" clearable></el-input>
        </div>

        <div class="search-item search-time"><span>开始日期:</span>
          <el-date-picker v-model="searchMsg.startDate" align="right" type="date" placeholder="选择开始日期"
                          value-format='yyyy-MM-dd'>
          </el-date-picker>
        </div>
        <div class="search-item search-time"><span>结束日期:</span>
          <el-date-picker v-model="searchMsg.endDate" align="right" type="date" placeholder="选择结束日期"
                          value-format='yyyy-MM-dd'>
          </el-date-picker>
        </div>
        <areaSelect v-on:getNowAreaPosition="getArea" :areaText="areaText"></areaSelect>
      </div>

      <div class="search-footer">
        <button class="search-btn" @click="searchServiceListsData">查询</button>
      </div>
    </div>

    <!--内容-->
    <div class="main-content">
      <div class="content-info">

        <!-- 111:表格数据与翻页合并模块 -->
        <DataTable :dataTableObj="dataTableObj" :childLoad="parentLoad" v-on:getPageNo="searchByPageNo" v-on:handlePageReload="pageReload"
                   v-on:getPageSize="searchByPageSize">
          <!--除查询外的操作-->

          <div slot="operate">
            <div class="some-operate">
              <!--<button class="some-btn">导出</button>-->
            </div>
          </div>
          <!-- 额外的操作以及其他因素 -->
          <div>
            <el-table-column fixed="right" align="center" label="操作" width="150">
              <template slot-scope="scope">
                <div class="item-route">
                  <div class="item-route-link" v-for="(item ,index ) in childLink" v-if="pagePower['003003001']"
                       @click="$goRoute( item.route +'?id='+ scope.row.id)">{{item.text}}
                  </div>
                </div>
              </template>
            </el-table-column>
          </div>

        </DataTable>
      </div>
    </div>
  </div>
</template>
<script>
  import moment from 'moment'  // 时间格式转化
  // 表格数据
  import DataTable from "../../../components/dataTable/dataTable"
  import areaSelect from "../../../components/areaSelect/areaSelect"

  import com from '../../../js/common'

  import HeadTop from "../../../components/head-top/head-top"
  import {getServiceList} from '@/api/getData'

  export default {
    name: 'serviceLists',
    components: {
      DataTable,
      areaSelect,
      HeadTop
    },
    data() {
      return {
        pagePower: JSON.parse(com.getStore('pagePowers'))['003003'] ? JSON.parse(com.getStore('pagePowers'))['003003'] : {}, // 权限
        parentLoad: '加载中...',    // 加载状态
        // 区域选择
        areaText: '区域选择:',
        searchData: {   // 前端定义的字段
          elCode: '',       // 注册代码
          repUserName: '',     // 维修责任人
          startDate: '',    // 开始时间
          endDate: '',      // 结束时间
          repStatus: '5',       // 状态
          elAreaCode: ''     // 查询地区code
        },
        childLink: [
          {
            route: '/manage/faultMgr/faultHistory/faultHisDetail/faultHisDetail',
            text: '查看详情'
          }
        ],
        dataTableObj: {
          // 表格数据
          tableData: [],
          // 表格标题
          tableColumns:
            [
              {
                text: '序号',
                width: '30',
                attributeName: 'index'
              },
              {
                text: '注册代码',
                width: '100',
                attributeName: 'elCode'
              },
              {
                text: '电梯类型',
                width: '80',
                attributeName: 'elTypeName'
              },
              {
                text: '安装地址',
                width: '160',
                attributeName: 'elArea'
              },
              {
                text: '完成时间',
                width: '100',
                attributeName: 'repEndDate'
              },
              {
                text: '维修责任人',
                width: '100',
                attributeName: 'repUserName'
              },
              {
                text: '故障来源',
                width: '100',
                attributeName: 'troubleFrom'
              },
              {
                text: '状态',
                width: '70',
                attributeName: 'repStatusName'
              }
            ],
          // 翻页的数据
          pageObj:
            {
              // 每页分为几条数据
              pageSize: 10,
              // 总共多少数据
              pageNum: 0,
              pageNo: 1,
              searchStatus: 2,
            },
        },
        searchMsg: {  // 后台查询条件(后台所需要的字段)
          elCode: '',       // 注册代码
          repUserName: '',     // 维修责任人
          startDate: '',    // 开始时间
          repEndDate: '',      // 结束时间
          repStatus: '5',      // (必传)故障历史状态
          elAreaCode: '',      // 查询地区code
        }
      }
    },
    mounted() {
      this.getArea()
      // 获取当前页面所需数据
      this.getFaultListsData()
    },
    methods: {
      // 获取页面所需数据
      getFaultListsData(obj) {

        this.dataTableObj.pageObj.searchStatus = 2
        this.dataTableObj.tableData = []
        let self = this;
        getServiceList({
          pageNo: self.dataTableObj.pageObj.pageNo,
          pageSize: self.dataTableObj.pageObj.pageSize,
          condition: self.searchMsg
        }).then(function (data) {

          self.dataTableObj.pageObj.searchStatus = 1
          let info = data.data.data
          let infoArr = info.data
          if (infoArr.length > 0) {
            infoArr.forEach(function (i, t) {
              i.index = (t + 1) + self.dataTableObj.pageObj.pageSize * (self.dataTableObj.pageObj.pageNo - 1)
              i.repEndDate = moment.unix(i.repEndDate / 1000).format('YYYY-MM-DD HH:mm:ss') // 完成时间
            });
          } else {
            self.parentLoad = '暂无数据'    // loading(暂无数据)
          }

          self.dataTableObj.tableData = infoArr
          self.dataTableObj.pageObj.pageNum = info.totalRecord
        }).catch(function (data) {
          self.parentLoad = data.data.message    // loading(查询失败)
          self.dataTableObj.pageObj.searchStatus = 1
        })
      },

      // 每页多少内容
      searchByPageSize(val) {
        this.dataTableObj.pageObj.pageSize = val;
        this.getFaultListsData()
      },
      // 切换第几页
      searchByPageNo(val) {
        this.dataTableObj.pageObj.pageNo = val
        // 切换每页数目
        this.getFaultListsData()
      },
      searchServiceListsData() {
        // 跳出查询等待框
        if (moment(this.searchData.endDate).isBefore(this.searchData.startDate)) {
          this.$message.warning('开始时间应小于结束时间')
          return
        }
        this.getFaultListsData()
      },
      getArea(res) {
        if (typeof(res) == 'object' && typeof(res.code) != 'undefined') this.searchMsg.elAreaCode = res.code
      },

      // 页面刷新
      pageReload(){
        this.getFaultListsData();
      }
    }
  }
</script>
<style lang="scss" type="text/scss">
  @import "../../../style/entry/components/pageCommon";
</style>
